Top 10k strings from MC Tutor (1985)(Hansoft)(Part 3 of 5).z80 in <root> / bin / z80 / software / Sinclair Spectrum Collection TOSEC.exe / Sinclair ZX Spectrum - Utilities & Educational / Sinclair ZX Spectrum - Utilities & Educational - [Z80] (TOSEC-v2007-01-01) /

Back to the directory listing

   3 DEFM "  ADD HL,HL
   2 the number
   2  LD HL,STORE
   2  LD HL,22528
   2  EXAMPLE OF RELATIVE JUMPS
   2  0 0 0 0 0 1 0 1    +5
   2   LD HL,STORE
   2   LD (HL),A
   2   DJNZ LOOP
   1 transfer (HL) to (DE), increment HL and DE, decrement BC, set PV flag if BC=0
   1 transfer (HL) to (DE), decrement HL, DE, and BC, set PV flag if BC=0
   1 the port whose number is in C
   1 the memory location (IY)
   1 the memory location (IX)
   1 the memory location (DE)
   1 the memory location (BC)
   1 the location (HL)
   1 the contents of the Accumulator is eXclusively ORed with
   1 the contents of
   1 the computer is HALTed until an interrupt comes to awake it again
   1 the carry flag is set, ie Set Carry Flag
   1 the carry flag is inverted, ie Compliment Carry Flag
   1 the alternative AF registers
   1 the accumulator is ComPared with
   1 the Stack Pointer
   1 the Refresh register
   1 the RETurn address is POPped from the stack
   1 the L register
   1 the Interrupt vector register
   1 the IY register
   1 the IX register
   1 the HL register
   1 the H register
   1 the Flag register
   1 the E register
   1 the DE register
   1 the D register
   1 the C register
   1 the BC, DE, HL registers are all EXchanged with the alternative set
   1 the BC register
   1 the B register
   1 the Accumulator is logically ORed with
   1 the Accumulator is logically ANDed with
   1 the Accumulator is NEGated, ie made negative
   1 the Accumulator
   1 the AF registers
   1 search from (HL) Incrementing BC bytes for data in Accumulator
   1 search from (HL) Decrementing BC bytes for data in Accumulator
   1 rotate the accumulator and carry Right
   1 rotate the Accumulator and carry Left
   1 rotate the Accumulator Right, shifting bit 0 into Carry
   1 rotate the Accumulator Left shifting bit 7 into Carry
   1 rotate Right Decimal contents of (HL) with least significant end of Accumulator
   1 rotate Left Decimal contents of (HL) with least significant end of Accumulator
   1 reSTart at address
   1 push the return address to stack and CALL
   1 port with the above number
   1 perform relative jump to
   1 perform jump to
   1 output from (HL) to port (C) increment HL, decrement B
   1 ouTput to port (C), from block from (HL) Decrementing HL for B bytes
   1 ouTput from (HL) to port (C) block from (HL) Incrementing for B bytes
   1 oUTput from (HL) to port (C) Decrement HL, decrement B
   1 memory location
   1 location (IY+offset)
   1 location (IX+offset)
   1 is loaded with
   1 is Shifted Right Logically, 0 is shifted into bit 7
   1 is Shifted Right Arithmetically, sign bit unchanged
   1 is Shifted Left Arithmetically, 0 is shifted into bit 0
   1 is Rotated Right, shifting bit 0 into Carry
   1 is Rotated Left shifting bit 7 into Carry
   1 is PUSHed onto the stack and the SP decremented by 2
   1 is POPped from the stack and the SP incremented by 2
   1 is INCremented by 1
   1 is EXchanged with
   1 is DECremented by 1
   1 invert all bits in A register, ie ComPLiment
   1 input data from
   1 if the Zero flag is set,
   1 if the Zero flag is not set,
   1 if the Sign flag is set, ie Minus,
   1 if the Sign flag is not set, ie Positive,
   1 if the Parity flag is sEt, ie Parity is Even,
   1 if the Parity flag is nOt set, ie Parity is Odd,
   1 if the Carry flag is set,
   1 if the Carry flag is not set,
   1 iNput into (HL) from port (C) increment HL, decrement B
   1 iNput into (HL) from port (C) Decrement HL, decrement B
   1 iNput from port (C), into block from (HL) Incrementing HL for B bytes
   1 iNput from port (C), into block from (HL) Decrementing HL for B bytes
   1 i.e. carry   ' '   ' '
   1 i.e. borrow    0 1 1 2   0 2
   1 i.e.  B8 hex = (B hex)* 16+ (8)* 1
   1 has taken from it the carry and
   1 has added to it the carry and
   1 has added to it
   1 enable Interrupts. NOT PERFORMED BY SIMULATOR.
   1 disable Interrupts. NOT PERFORMED BY SIMULATOR.
   1 decrement B, if zero continue, if Not Zero perform relative jump to
   1 decimal Adjust Accumulator
   1 compare (HL) with A, increment HL, decrement BC
   1 compare (HL) with A, decrement HL, and BC
   1 change Interrupt Mode to
   1 block transfer (BC) bytes starting at (HL) to (DE) incrementing
   1 block transfer (BC) bytes starting at (HL) to (DE) decrementing
   1 and Carry are rotated Left
   1 and Carry are Rotated Right
   1 This is the number we  originally  assumedat the beginning of our discussion.
   1 The Accumulator has subtracted from it
   1 Space missing
   1 Since   the  contents of the  HL  registerpair can be the result of some calculationthe jump can be conditional.
   1 RETurn from Non-maskable interrupt: NOT PERFORMED BY SIMULATOR
   1 RETurn from Interrupt: NOT PERFORMED BY SIMULATOR
   1 One  difficulty  with the  above  types ofjump is that,  if the start address of theprogram   were  changed,   all  the   jumpaddresses   would  require   modification.Relative   jumps   do   not   have    thisdifficulty.  The absolute  address is  notstored  with  the  instruction. It is  thedifference between the current contents ofthe  program   counter and the  address towhich  we  wish  to jump  that  is  storedwithin the instruction. Relative jumps arelimited to jumping backwards 128 locationsand forwards 127 locations.
   1 Offset too big
   1 Offset missing
   1 Number too large
   1 Number missing
   1 No OPeration is performed, inspite of this it takes .
   1 No DEFB, or DEFW
   1 NOT DEFINED
   1 Missing space or ,
   1 Label too long
   1 Label not found
   1 JP Z,nn   jump on zero
   1 JP NZ,nn  jump on not zero
   1 JP NZ,nn    jump if zero  flag not set
   1 JP NC,nn  jump on no carry
   1 JP NC,nn    jump if carry flag not set
   1 JP C,nn   jump on carry
   1 Instruction unknown
   1 Hence to make a  positive  number negativewe invert all its binary  bits,  known  asComplimenting, and add 1.  The notation isgenerally termed 2s complement
   1 FLAGS$    Registers and Contents   % STAC
   1 Error after inst.
   1 EXAMPLES OF BINARY CODED DECIMAL NOTATION
   1 EX5B:DEFM " LD HL,(STORE)
   1 EFM "  INC DE
   1 DJNZ e    decrement and jump on  non zero
   1 DEFM "using addition to successively multiply by"
   1 DEFM "number held in the HL register pair by  10"
   1 DEFM "  LD HL,(STORE)
   1 DEFM "  LD DE,(STORE)
   1 DEFM "  LD (STORE),HL
   1 DEFM "  JR LOOP1
   1 DEFM "  INC HL
   1 DEFM "  INC H
   1 DEFM "  DJNZ LOOP2
   1 DEFM "  ADD HL,DE
   1 Cursor keys, delete,  and auto-repeat are as standard. BREAK returns you to menu.
   1 Can only ADD IX/IY
   1 Bracket missing
   1 ADDRESS MACHINE CODE
   1 101, which is  1  less  thanthat  for -2.
   1 10.   Bit 7, the most significantbit,  represents  the  sign ( + or - )  ofthe number.  When bit 7 is  "1" the numberis negative,  and when  "0"  the number ispositive.
   1 10 for an example.Inverting all bits of the binary number of+2 gives 
   1 1, or  the  processor  would notbe able to take  6  from  5  and  get  theright answer.   Further  5 - 7 = -2 or 254or 
   1 1   or  127  and   the  largestnegative number 1
   1 010  and  its negativeequivalent -2  or 
   1 01 seconds to do it
   1 0 or -128.
   1 -^1^>^E^V^O^]^j^q^{^
   1  where e is the displacement   inJR NC,e   the range 127 to -128
   1  the    standardcalculation.
   1  since each  digit  can have  one  of  tenstates, designated 0 - 9.
   1  operation.
   1  of the Accumulator.
   1  jump if zero  flag set
   1  jump if carry flag set
   1  i.e.  -2  is equivalent to 254 etc.
   1  ectively  multiplies  a"
   1  contents  of  the  Accumulator   by
   1  complementing  and  adding 1 in one
   1  bit    7   6   5   4    3   2   1   0
   1  as BC, DE, HL,or SP.
   1  You are trying to run code in allocated storage area. RET missing? Please EDIT 
   1  You are about to write to memory which   will affect your program. Please edit it.
   1  You are about to affect memory area not  allocated to you. Please edit program.   
   1  When  performing   arithmetic  operationswhich  we  wish  to  interpret  within therange  -128 to +127,  the  Carry  flag  nolonger  signals  an out  of  range result.However another  flag, the overflow  (P/V)flag does. It is a "1" whenever the answeris outside the range  -128 to +127 and "0"within  the  range.  It  is  effectively acarry into bit 7 which would make the signbit incorrect.
   1  We would still like to be able to performcalculations  on  decimal  numbers withouthaving to convert to binary or hexadecimalform.  Hexidecimal form  holds  a key to amethod of achieving this.
   1  We  shall  then  look at  numbers held inregisters in more detail.
   1  We  require   16  different   symbols  torepresent  a  digit.   0-9  gives  us  thefirst  10  and  A-F  the final 6.   A listof   decimal,   binary,  and   hexadecimalequivalents  are given on the next screen.
   1  To perform  this  operation  the Z80 usestwo  further  flags, the  H  flag ( a Halfcarry  between  nibbles ),   and   N  flag( subtract  instruction  performed last ).Since these flags cannot be tested as partof a  conditional  jump etc. they  are  oflittle use.
   1  To  get  round this problem  use a label,declaring  it in the label column in frontof the  instruction  to which  you wish tojump.
   1  Thisinstruction is used after  an  8  bit ADD,ADC, SUB, or SBC to adjust the Accumulatorcontents  by  adding  6  to the nibble, ifeither nibble in the answer is above 9.
   1  This simple example counts up the  numberof memory locations holding a number above192  and below  64 in the first  32 memorylocations.
   1  This presentation is termed  Binary CodedDecimal or BCD.
   1  This  example  illustrates  a  method  ofmultiplication.  There  are  other  fastermethods that will be shown later.
   1  They are simply those in  which DE, or BCcan take part. The instruction  equivalentto EX DE,HL  is however  EX (SP),HL,  thatEXchanges the  contents  of  the bottom ofthe Stack with the HL register.
   1  These  examples  show simple addition andsubtraction in  BCD format.   Remember  tokeep  in    Hex   display   mode   or  theillustrations will not appear in BCD.
   1  There is no reason for sticking to 8 bitsusing this method.  So long as the  numberof  bits  is  sufficient   and  the   mostsignificant bit is taken as  the sign  bitany size positive or negative  number  canbe represented.
   1  There are too many registers called up,  to display. Program will RUN as normal. 
   1  There  is  one particular  relative  jumpinstruction  that is particularly   usefulnamely Decrement and Jump on Non-Zero,  orDJNZ.   The B register is decremented and,if  the result is not zero,  the processorperforms  a relative jump to the  computednew address.  If  the  result is zero thenthe next instruction in sequence is taken.DJNZ  allows  us  to  repeat  a  series ofinstructions a preset number of times. Thenumber of repeats is equal to the contentsof  the   B  register  when  the  loop  isentered, so long as  the  B  register doesnot   form   part   of   the   series   ofinstructions.
   1  The stack pointer is outside allocated   memory area. Please edit program.
   1  The simulator uses the memory area  32000to  32255  for  the  pupils  programs. TheStack Pointer is initially  set to  32254,and works its way down towards the programarea.  Keep the SP at the top end of  thisarea  of   memory  to   ensure  that   thesimulator does not stop.
   1  The simplest  jump is JP nn,  where nn isthe  address  to  which the  program is tojump. This is  an  unconditional jump, theProgram  Counter  always  jumping  to  theaddress nn.
   1  The program has been completed. You may  EDIT or reRUN. Exit by pressing BREAK.   
   1  The mnemonic for relative jumps is JR andcan  take  all the forms discussed  so farfor JP,  i.e.  JR , JR NC, JR C, JR NZ andJR Z.
   1  The maximum number that can be held in an8  bit  register  is
   1  The last four pairs of  memory  locationsin the  Stack are  displayed at the bottomright hand corner of the screen.   As withthe Program Counter, the position to whichthe Stack Pointer points is shown in Cyan.
   1  The instruction is PUSH dd. Continuing toPUSH  data on to the Stack  results in thedata  being pushed in at the bottom of theStack  and the Stack Pointer  working  itsway down through memory.
   1  The instruction INC SP is included at theend of the program  to  ensure  that SP isdisplayed.  The  actual  value  in the  SPregister is  immaterial  for  most  of itsapplications.
   1  The assembler, within this tutor, has oneinstruction   not  normally  found  in  anassembler,   namely   BIN.  The  assemblerallocates one memory location to the line,which  would  normally  be  labelled.   Itconstantly   displays  this   location  inbinary form.  The number  after BIN is thenumber   initially   inserted   into   thelocation.
   1  The Spectrum works on  32 characters  perline and not 42 as does the TUTOR
   1  The BC, DE and HL registers may be PUSHedon to  and  POPped  from  the  Stack.  TheAccumulator may also be  PUSHed on to  theStack,  but  this  is  done with the  flagregister F, which will be discussed later.
   1  The  return  instruction  RET,  POPs  thereturn address from the Stack,  back  intothe  PC  register,  to continue where  themain program left off.   If the  number ofPUSHes  and CALLs in the  subroutine  doesnot equal the number of  POPs and RETurns,obviously this will not happen.
   1  The  processor,  under  the  programmer'sdirection,  has   the   capacity  to  makedecisions.  In  the  following  lessons weshall discuss these instructions that makea computer more than just a calculator.
   1  The  location  23060  holds a number  256less  than   the  start  of  the  Spectrumcharacter   set.   This   example   writescharacters  along  the  top  line  of  thescreen.   Once   you  have   followed  theindividual steps of the  program,  keepinga key  pressed will result in the  programbeing stepped through quickly.
   1  The  largest  positive number we can holdin a single register,  using this notationis  0
   1  The  hex  digit  requires  adjustment  toavoid the digits  A-F.  Adding  6  to  thedigit, if these symbols appear, results incorrect adjustment.
   1  The  aspect  of  a computer that makes itmore than a calculator is  its ability  tochange  its  sequence of operations  as  aresult  of  earlier  instructions.  Withinthe  Z80  there  is  a counter  called theProgram Counter or PC. This counter  keepstrack of which  instruction  the processoris  to  perform  next.  By  modifying  itscontents, the  processor can be  jumped toany instruction in memory.
   1  The  arrangement of the screen, and otheruseful   memory   locations   within   theSpectrum are given in the TUTOR manual.
   1  The  Z80 has two instructions that may beused for these operations
   1  The  Stack is an area of external  RandomAccess Memory, that is used as a series ofregister  pairs,  in  conjunction  with  aStack Pointer. The Stack Pointer (SP) is asingle  double  length register within theZ80, capable of holding up to 65335.
   1  The  Stack  Pointer  can  take  part in anumber of instructions already discussed.
   1  The  Simulator  can  be  switched betweendecimal   and   hexadecimal   display   bypressing  "g",  when  a  program  is   notrunning.
   1  The  Sign  and  overflow  flags  are alsooperative after ADC and SBC instruction onthe HL register. It reflects the  15th bit(or bit 7 of H register) .
   1  The   operation   luckily  also  makes  anegative   number    positive.   A    veryimportant point.
   1  The   first  example  shows  nesting   ofsubroutines :  a subroutine  being  calledfrom within another subroutine.
   1  The   conditional   jumps  involving  thecarry and zero flags are:-
   1  The   Z80  allows  this  feature  by  theinstruction CALL.  The CALL instruction issimilar to the JP instruction except  thatthe   address  of  the   next   sequentialinstruction, held in the  PC  register, isPUSHed onto the Stack, prior to the jump.
   1  The   Z80    accommodates    the    aboveadjustment,  with  the  instruction   DAA,Decimal    Adjust    Accumulator.
   1  The    more    powerful   jump   is   theconditional jump.  The processor tests thestate of a flag,  before either jumping orcontinuing in  sequence.
   1  Taking  our  number 10111000  for exampleand   noting   that   bits  that  are  "0"contribute  nothing  to  the  number,  thedecimal equivalent of 10111000 is given by
   1  Take the hex number C (= 12 dec.). Adding6 gives 18 decimal or 12 hex.   Hence  thehex number looks  identical to the decimalanswer required.
   1  THE STACK
   1  Summary - the Stack and SP register
   1  Summary - relative jumps
   1  Summary - jumps
   1  Summary - calls and returns
   1  So far we have only dealt  with  positivenumbers. If we had taken 6 from 5 we wouldend up with the answer 255  with the carryset.  There is an interpretation of binarynumbers  that  allows  us to consider thisanswer as the negative number -1.
   1  Similar we can perform subtraction.
   1  STORE DEFW 0
   1  STORE DEFB 64
   1  STORE DEFB 6
   1  STORE DEFB 124
   1  STORE BIN 15
   1  SR2   LD A,(HL)
   1  SR1   CALL SR2
   1  SOURCE CODE   
   1  SBC HL,SP
   1  Return to operating system
   1  RET NZ    Not Zero
   1  RET NC    No Carry
   1  RELATIVE JUMPS
   1  Program stopped. You may re-RUN, EDIT or press BREAK to return to menu.  
   1  Program has successfully assembled. Press RUN, EDIT, or exit by pressing BREAK. 
   1  Program counter has jumped to non-valid  address. EDIT or reRUN program.
   1  Press SPACE to select and ENTER to start
   1  Press SPACE to continue.
   1  Press RUN to begin example, EDIT to edit, and BREAK to return to menu.
   1  Please confirm disk loading required  Y/N
   1  Performing  a  similar calculation to theabove we can show that a register pair canrepresent a number in the  range +32767 to-32768.
   1  PUSH DD  where  DD  is AF, BC, DE, or HL.
   1  POP dd retrieves data from the Stack intothe defined  register  pair.  The registerpair  is  loaded with the contents of  thememory location pointed to by SP. Then theSP register is incremented twice.
   1  Now that hex notation has been introducedwe  can  discuss  how  the computer storesprograms  in  more  detail.    As  alreadymentioned, the  instructions are stored inmemory as numbers.  Some instructions onlyrequire a single  number,  others  requiremore.  Column 2  on  the Simulator displayshows   the   memory  contents   for   theinstructions in hex form.
   1  No   flags   are  affected  by  any  jumpinstructions including DJNZ.
   1  NUM2  BIN 95
   1  NUM1  BIN 81
   1  NEG   negates,  or  makes  negative,  the
   1  Luckily  assemblers  takes account of allthese  complexities,  and  you will not berequired    to   learn   the   tables   inAppendix A of your Spectrum Manual.
   1  Loading lessons 26-35
   1  Loading lessons 18-25
   1  Loading lessons 10-17
   1  Loading lessons 1-9
   1  Loading has been stopped
   1  Loading error
   1  Load further lessons from disk
   1  Lessons 10 - 17
   1  LOOP2 LD A,(DE)
   1  LOOP2 DEC (HL)
   1  LOOP1 LD (STORE),HL
   1  LOOP1 LD (HL),A
   1  LOOP  LD A,(HL)
   1  LOOP  DEC (HL)
   1  LOOP  ADD HL,DE
   1  LD SP,(nn)
   1  LD HL,56789
   1  LD DE,(23606)
   1  LD (nn),SP
   1  Just  as   we  add  two  decimal  numberstogether,  carrying one forward if the sumof two  digits is  greater  than 9, we canadd two  binary numbers.  If  the  sum  isabove one, a one is carried forward.
   1  It must be remembered that  a  subroutinemay  require the use of a  register  whosecontents  are still  required in the  mainprogram.  Its  contents must  therefore bePUSHed  onto the stack or otherwise storedelsewhere, and retrieved at the end of thesubroutine.
   1  It is important to remember that the ZeroCarry, Sign, and overflow flags are alwaysoperative   after  an   8  bit  arithmeticinstruction or a 16 bit addition involvingthe  Carry.   Your  interpretation  of theresult determines which flag(s) you shouldbe interested in.
   1  Indirect jumps are  also available on theZ80   using  the  HL   register  pair. Theinstruction   JP (HL)  loads  the  programcounter    with  the  contents  of the  HLregister.  Thus   the  address of the nextinstruction  to be performed   is    equal to the contents of the HL register.
   1  In this interpretation  -1 must equal 255or 
   1  In a register each digit  or bit has onlytwo states. Therefore we can interpret thedigits as having weightings of
   1  If we were to take the top off a Z80 chipand, using a powerful  microscope, look ata register,  we would see that it consistsof 8 cells.  These  cells  are  capable ofbeing   switched   between  two  differentstates.  Conventionally  we  designate onestate  as  "1"  and  the other as "0". Thepattern of 1's  and 0's  could be 10111000say.
   1  If the condition is not met,  the programwill  not  CALL the  subroutine  or RETurnfrom it.
   1  If  a series of registers is PUSHed on tothe Stack, and subsequently POPped off theStack, they reappear in the reverse order.
   1  INTRODUCTION
   1  How  do we  interpret this pattern?   Theamswer is, anyway we like.  In this lessonwe  show   that  this   pattern  could  be184, -72, B8H, and even CP B. The only onethe  processor  has  built  into it is thelatter.
   1  HEXADECIMAL NOTATION
   1  From now on dd can be considered
   1  Ex - unconditional calls & rets
   1  Ex - relative jumps 2
   1  Ex - relative jumps 1
   1  Ex - pushes and pops
   1  Ex - jumps
   1  Ex - hex notation
   1  Ex - conditional calls
   1  Ex - binary notation
   1  Ex - BCD notation
   1  Ex - +ve and -ve numbers
   1  Each digit in a number can  be consideredto have a weighting.  For decimal  numbersthese weightings are
   1  Each  digit  is  held  in  4  bits of theregister.   These  4  bits  are  called  anibble,  the whole  8 bit word is termed abyte.   Who said programmers have no senseof humour?
   1  EXAMPLES USING THE STACK
   1  EXAMPLES OF JUMPS
   1  EXAMPLES OF HEXADECIMAL NOTATION
   1  EXAMPLES OF BINARY NOTATION
   1  EXAMPLES OF +VE AND -VE NOTATION
   1  EXAMPLE OF CONDITIONAL CALLS
   1  EXAMPLE OF CALLS TO SUBROUTINE
   1  EX (SP),HL
   1  Disk V1.0 (c) HanSoft '85
   1  Conversion of a hex number to its decimalequivalent
   1  Continuing  to  POP data from  the  Stackresults  in information being POPped  fromthe  bottom  of the Stack  and  the  StackPointer  working  its way back up  throughthe memory.
   1  Carry set
   1  CPL   complements or inverts the contents
   1  CALLS TO SUBROUTINES
   1  Both conditional and unconditional  CALLsand RETurns are available on the Z80.  Allfour   types    of   conditions    alreadyconsidered  ( NC, C, NZ  and  Z )  can  beused with CALLs and RETurns.
   1  Binary  numbers  are too  cumbersome  anddecimal  too   inconvenient   to   displaymultiple  register  numbers.   A method ofpresenting   binary   numbers   has   beendeveloped  to  get  round  these problems.Instead of  basing  the number on 10 as indecimal or 2 as in binary,  we  base it on16.  This  numbering   system  is   calledHexadecimal.
   1  Before   loading   the  Stack  from   anyinternal register pair,  the Stack Pointeris decremented  twice, ( thus pointing  tothe  next pair of memory locations ).  Thecontents of the  register is  then  loadedinto the  Stack  indirectly  using the  SPregister as the address.
   1  BINARY NOTATION
   1  BINARY CODED DECIMAL NOTATION
   1  BELOW INC D
   1  Always  remember that a hex  number has abase of 16 decimal, a decimal number has abase of 10  and a  binary number a base of2.
   1  Although you can enter the address withinthe jump in  number  form,  if it does notequal the  address  of  the  start  of  aninstruction,  the simulator  will stop  atthe  JUMP.  This is because  the processorwould  perform  the  instruction  it findsat that address and anything could happen,and usually does.
   1  Although  these examples appear to be allpositive, they  can  be  viewed equally asnegative where appropriate  and  the  Signand  overflow  flags  observed  operating.Remember a  number above 128 is a negativenumber. Since all the negative numbers  inthe examples are small,  they  can be seenquickly   and   simply  be  converted   bysubtracting the number from 256.
   1  All assemblers calculate the displacementfor relative jumps.   The assembler withinthis TUTOR is no exception. Relative jumpsshould be entered with labels.
   1  All  the  numbers  used  to  describe  aninstruction  are  given in  sequence alongthe line. Notice that numbers called up inan  instruction  appear towards the end ofthe string of numbers. The earlier numbersdetermine the type of instruction.   Sincethe  total  number of  instructions exceed256, a  prefix  number  is used to produceother sets of instructions.   The prefixesyou will find are EDH, CBH, DDH and FDH.
   1  All  16  states of  the 4 binary bits arecovered by  0-F.  Hence only 2 hexadecimaldigits   are   required  to  display   thecontents of an 8 bit register. Our example10111000  divides  up into  1011  1000  orB8 Hex.  A  double  register  holding  say11001001 10111000  will  be represented byC9B8 hex.
   1  ANS   DEFW 0
   1  ANS   BIN 0
   1  ADD HL,SP
   1  ADC HL,SP
   1  ABOVE INC E
   1  A subroutine is a part of a program  thatis  called from the main program and  oncecompleted   returns  back  to   the   mainprogram.  The subroutine is usually calledfrom a number of places in the program.
   1  A Sign flag  (S) is  provided on the Z80.It  duplicates  the sign ( bit 7 ) of  theanswer after  any  arithmetic operation onthe Accumulator. The sign flag is  "0" fora positive result  and  "1" for a negativeresult.
   1  A  useful  operation  would  be to make apositive  number negative. Changing  bit 7does  not  do  this.   Take  the  positivenumber  2  or  
   1  = 11*16+8=184
   1  3    2    1
   1  17. Positive and negative notation
   1  16. Binary Coded Decimal notation
   1  15. Hexadecimal notation
   1  14. Binary notation
   1  13. Calls to subroutines
   1  128+64+32+16+8+4+2+1=255
   1  128+32+16+8=184.
   1  128  64  32  16   8   4   2   1
   1  12. The Stack
   1  11. Relative jumps
   1  1000  100   10    1
   1  10. Conditional and unconditional jumps
   1  1 1 1 1 1 0 1 1    -5
   1  1 0 0 1 0 0 1 1
   1  0 1 1 0 1 1 1 0
   1  0 1 1 0 0 1 1 0
   1  0 0 1 1 1 0 0 1
   1  -  0 0 1 0 1 1 0 1
   1  +  0 0 1 0 0 1 0 1
   1  &    clears all  ENTER tabs to next line STOP  assembles   SPACE tabs in label are
   1   Loading error
   1   LD HL,NUM2
   1   LD HL,4589H
   1   LD HL,16384
   1   LD HL,(STORE)
   1   LD E,(HL)
   1   LD DE,FFFEH
   1   LD DE,3812H
   1   LD DE,34567
   1   LD DE,2468H
   1   LD BC,12345
   1   LD B,(HL)
   1   LD A,(NUM1)
   1   LD (ANS),HL
   1   LD (ANS),A
   1   JR NZ,LOOP
   1   JR LOOP1
   1   JP NZ,LOOP2
   1   JP NZ,LOOP1
   1   INC (HL)
   1   Error  found  during  assembly. Please  correct before running program.
   1   EX (SP),HL
   1   DJNZ SR1
   1   DJNZ LOOP2
   1   CALL SR1
   1   CALL NC,ABOVE
   1   CALL C,BELOW
   1   ADD HL,DE
   1   ADD A,128
   1   ADD A,(HL)
   1    CALL Z,nn
   1    CALL NZ,nn
   1    CALL NC,nn
   1    CALL C,nn
   1    ASSEMBLED CODE   LABELS INSTRUCTIONS
   1     invert   1 1 1 1 1 0 1 0
   1     invert   0 0 0 0 0 1 0 0
   1     POSITIVE AND NEGATIVE NUMBER NOTATION
   1     Enter the Z-80 simulator ?   Y/N  
   1     Decimal   Binary    Hexadecimal